﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Hotnet.Biz.NSBizPicture;
using Ninject.Core;
using Hotnet.Biz.NSBizVideo;
using Hotnet.Biz.NSBizNews;
using Hotnet.Biz.NSBizMusic;

namespace Hotnet.Web.Filters
{
    public class AdminFilterAttribute : ActionFilterAttribute
	{
		private BizPictureCategory bizPictureCategory;
		private BizPictureCategory BizPictureCategory
		{
			get
			{
				if (bizPictureCategory == null)
				{
					bizPictureCategory = new BizPictureCategory();
				}
				return bizPictureCategory;
			}
		}
		private BizVideoCategory bizVideoCategory;
		private BizVideoCategory BizVideoCategory
		{
			get
			{
				if (bizVideoCategory == null)
				{
					bizVideoCategory = new BizVideoCategory();
				}
				return bizVideoCategory;
			}
		}
		private BizNewsCategory _BizNewsCategory;
		private BizNewsCategory BizNewsCategory
		{
			get
			{
				if (_BizNewsCategory == null)
					_BizNewsCategory = new BizNewsCategory();
				return _BizNewsCategory;
			}
		}

		private BizMusicCategory _BizMusicCategory;
		private BizMusicCategory BizMusicCategory
		{
			get
			{
				if (_BizMusicCategory == null)
					_BizMusicCategory = new BizMusicCategory();
				return _BizMusicCategory;
			}
		}


		public override void OnActionExecuting(ActionExecutingContext filterContext)
		{
			if ((filterContext.ActionDescriptor.ActionName == "Index" || filterContext.ActionDescriptor.ActionName == "AdminLogin") &&
				filterContext.ActionDescriptor.ControllerDescriptor.ControllerName == "Admin" || filterContext.ActionDescriptor.ActionName == "UploadImage")
				return;

			//if (filterContext.HttpContext.Session["_USER_"] == null)
			//{
			//    filterContext.HttpContext.Response.Redirect("/adminlogin");
			//}
		}

		public override void OnActionExecuted(ActionExecutedContext filterContext)
		{
			ViewDataDictionary ViewData = filterContext.Controller.ViewData;
			ViewData["PICTURE_CATEGORY"] = BizPictureCategory.List<int>(pc => pc.OrderNo ?? 0, false);
			ViewData["VIDEO_CATEGORY"] = BizVideoCategory.List<int>(vc => vc.OrderNo ?? 0, false);
			ViewData["NEWS_CATEGORY"] = BizNewsCategory.List<int>(nc => nc.OrderNo, false);
			ViewData["MUSIC_CATEGORY"] = BizMusicCategory.List<int>(nc => nc.OrderNo, false);
		}
	}
}
